import type { Config } from 'drizzle-kit';
import dotenv from 'dotenv';

// Load environment variables
dotenv.config();

// Get the database URL from env
const dbUrl = process.env.POSTGRES_URL || '';
const isPGlite = dbUrl.startsWith('pglite://');

// For migrations with PGlite, we'll use a temporary PostgreSQL URL
// This is because drizzle-kit doesn't support PGlite directly for migrations
// You'll need to manually apply the migrations using the db:migrate command
const migrationUrl = isPGlite 
  ? '' // Empty URL for PGlite (migrations will need to be applied manually)
  : dbUrl;

export default {
  schema: './lib/db/schema.ts',
  out: './lib/db/migrations',
  dialect: 'postgresql',
  dbCredentials: {
    url: migrationUrl,
  },
} satisfies Config;
